/**
 * 
 */
package de.oszimtcc.timetableadapter;

import java.util.ArrayList;
import java.util.List;

import android.R.color;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import de.oszimtcc.timetable.R;
import de.oszimtcc.timetable.TimetableApplication;
import de.oszimtcc.timetablecore.Block;
import de.oszimtcc.timetablecore.Block.BlockType;
import de.oszimtcc.timetablecore.Day;
import de.oszimtcc.timetablelistener.HideAfterEndAnimationListener;


/**
 * @author Kooki
 *
 */
public class ClassAdapter extends ArrayAdapter<String>
{
	private Context mContext;
	private List<String> classList = new ArrayList<String>();
	private int selectedPos = -1;
	
	public ClassAdapter(Context pContext, List<String> pClassList) 
	{
		super(pContext, 0);
		mContext = pContext;
		this.classList = pClassList;
	}
	
	@Override
	public int getCount() 
	{
		return (classList != null ? classList.size() : 0);
	}

	public String getClass(int pPosition) 
	{
		if(classList == null || classList.isEmpty() || pPosition > classList.size() - 1) 
		{
			return null;
		}
		
		return classList.get(pPosition);
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) 
	{
		View v = new View(mContext);
		if (convertView == null) 
		{
			LayoutInflater vi = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.item_classlist, null);
            
		} 
		else 
		{
			v = convertView;
		}
		
		if(position == this.selectedPos)
			v.setBackgroundColor(Color.RED);
		else
			v.setBackgroundColor(color.background_dark);
		
		TextView text = (TextView) v.findViewById(R.id.item_classlist_entryvalue);
        text.setText(this.getClass(position));
        v.setTag(text.getText());
		return v;
	}

	public List<String> getData() 
	{
		return classList;
	}

	public void setData(List<String> pClassList) 
	{
		this.classList = pClassList;
	}
	
	public void setSelectedPosition(int pos)
	{
		selectedPos = pos;
		notifyDataSetChanged();
	}

	public int getSelectedPosition()
	{
		return selectedPos;
	}
}
